﻿<style>

</style>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class='layui-form-item'>
        当前选中<span style="color:red" id="goodnum"></span>个商品
    </div>
    <div class='layui-form-item'>
        <label class="layui-form-label">非店铺会员不可购买</label>
        <div class='layui-input-inline'>
            <select id="IsMember" name="IsMember">
                <option value="">无限制</option>
                <option value="1">是</option>
            </select>
        </div>
        <span style="color:green">选“是”表示只有店铺会员才能购买商品</span>
    </div>
    <div class='layui-form-item'>
        <label class="layui-form-label">指定购买会员等级</label>
        <div class='layui-input-inline'>
            <select name='MemberLevel' xm-select="MemberLevel" id='MemberLevel'>
                <option value=""></option>
            </select>
        </div>
        <span style="color:green">指定会员等级的用户才可购买</span>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn layuiadmin-btn-list" data-type="confirm">确定</button>
        </div>
    </div>
</div>
<script>
     
    var form, admin, $;

    layui.use(['form', 'admin', 'table', 'formSelects'], function () {
        var $ = layui.$
        , admin = layui.admin
        , view = layui.view 
        , form = layui.form;
        var table = layui.table;
         
        $("#goodnum").text(checkids.length);


        var formSelects = layui.formSelects;
        formSelects.config('MemberLevel', {
            keyName: 'Name',            //自定义返回数据中name的key, 默认 name
            keyVal: 'Xh',            //自定义返回数据中value的key, 默认 value
        });

        admin.req({
            url: layui.setter.APIUrl + '/shop/Member_levelMgr/customerQuery', //实际使用请改成服务端真实接口
            type: 'post',
            done: function (res) {
                layui.formSelects.data('MemberLevel', 'local', {
                    arr: res.Data,
                });
            }
        });


        var active = {
            confirm: function () { 
                if (checkids.length === 0) {
                    return layer.msg('请选择商品');
                }
                var IsMember = $("#IsMember").val();
                var MemberLevel = formSelects.value('MemberLevel', 'valStr');
                var ids = JSON.stringify(checkids);

                var index = layer.load(1); 
                admin.req({
                    url: layui.setter.APIUrl + '/shop/goodsMgr/GoodLimit' //实际使用请改成服务端真实接口
                  , data: { "ids": ids, "IsMember": IsMember, "MemberLevel": MemberLevel }
                  , type: "post"
                  , done: function (res) {
                      layer.close(index); //执行关闭
                      layui.table.reload('LAY-app-content-list'); //重载表格
                      layer.closeAll();
                      layer.msg('购买限制更新成功');
                  }
                });
            },
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
